import cv2 as cv


image = cv.imread('/Users/apple/Desktop/data/lena.jpg')
image = cv.pyrDown(image)
greImg = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
cv.imshow('grey image', greImg)



# 分别对x，y求导
x = cv.Sobel(greImg, cv.CV_16S, 1, 0)
y = cv.Sobel(greImg, cv.CV_16S, 0, 1)

# 将Sobel建立的图像位数转回原来的uint8形式
absX = cv.convertScaleAbs(x)
absY = cv.convertScaleAbs(y)

# 组合x，y方向
dst = cv.addWeighted(absX, 0.5, absY, 0.5, 0)
cv.imshow("absX image", absX)
cv.imshow("absY image", absY)
cv.imshow("Sobel image", dst)



# Canny算子
GasImg = cv.GaussianBlur(greImg, (3, 3), 0)
edge = cv.Canny(GasImg, 50, 150)
cv.imshow('Canny image', edge)


cv.waitKey()
cv.destroyAllWindows()
